package cn.tedu.order.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

//一阶段
@LocalTCC
public interface OrderTCCAction {
    /*
    BusinessActionContext
    TCC 的上下文对象,通过ctx对象,在两个阶段传递业务数据

    @BusinessActionContextParameter 注解
    吧数据放入上下文对象,通过上下文对象可以吧数据传递到第二阶段
     */
    //Try
    //指定二阶段方法名
    @TwoPhaseBusinessAction(name = "OrderTCCAction")
    boolean prepare(
            BusinessActionContext ctx,
            @BusinessActionContextParameter(paramName = "id") Long id,
            @BusinessActionContextParameter(paramName = "userId")Long userId,
            @BusinessActionContextParameter(paramName = "productId")Long productId,
            @BusinessActionContextParameter(paramName = "count")Integer count,
            @BusinessActionContextParameter(paramName = "money")BigDecimal money
            );

    //Confirm 提交
    boolean commit(BusinessActionContext ctx);

    //Cancel 取消
    boolean rollback(BusinessActionContext ctx);
}
